<template>
	<view class="swiper-list" :style="{height:`${height}px`}">
		<swiper class="list" :current="current" :style="{height:`${height}px`}" :vertical="true"
			:nextMargin="`${nextMarginHeight}px`" :duration="300">
			<swiper-item class="item" >
				<view class="inner" >
					<view class="user-info" @click.stop="toUserInfo(product.user.uid)">
						<view class="avatar">
							<image class="img" :src="product.user.avatar||''" mode="widthFix"></image>
						</view>
						<view class="nickname">
							<view>{{product.user.nickname}}</view>
							<view>发布件数：{{product.user.publish_num}} 件</view>
						</view>
					</view>
					<swiper class="slider-image" autoplay indicator-dots circular :duration="500">
						<swiper-item v-for="(pic, i) in product.slider_image" :key="i">
							<image class="slider-pic" :src="pic" mode="aspectFill"></image>
						</swiper-item>
					</swiper>
					<view class="goods-item v-ellip-2">[{{product.id}}]{{product.store_name}}</view>
					<view class="goods-item color-red">￥{{product.price}}
						<text v-if="product.wear_txt" class="separate">|</text>{{product.wear_txt||""}}
						<text v-if="product.made_at" class="separate">|</text>{{product.made_at||""}}
					</view>
					<view class="goods-item" v-if="product.cate_names">{{product.cate_names}}
						<text v-if="product.mType"><text class="separate">|</text>{{product.mType.title||""}}</text>

					</view>
					<view class="goods-item1" v-if="product.stock">
						<view>
							商品库存：<text class="color-desc">{{product.stock}}</text>
						</view>
						<view class="godetail" @click="toDetail(product)">
							查看详情
						</view>
					</view>
					<!-- 					<view class="goods-item" v-if="item.factory_name">生产厂家：<text class="color-desc">{{item.factory_name}}</text></view>
					<view class="goods-item" v-if="item.model">商品型号：<text class="color-desc">{{item.model}}</text></view>
					<view class="goods-item" v-if="item.piece_no">商品件号：<text class="color-desc">{{item.piece_no}}</text></view>
					<view class="goods-item" v-if="item.intro">商品配置：<text class="color-desc">{{item.intro}}</text></view>
					<view class="goods-item" v-if="item.from_addr">发货地址：<text class="color-desc">{{item.from_addr}}</text></view>
					<view class="goods-item" v-if="item.store_info">描述文字：<text class="color-desc">{{item.store_info}}</text></view>
					<view class="goods-item" v-if="item.service_desc">售后描述：<text class="color-desc">{{item.service_desc}}</text></view>
				 -->
				<view class="tuijian">
					<image class="tuijianicon" src="../../static/images/group02.gif" mode=""></image>
					为你推荐
				</view>
				</view>

			</swiper-item>

			
			<swiper-item class="item" :style="{height:`${height}px`}" v-for="(item, index) in list" :key="index">
				<view class="inner" >
					<view class="user-info" @click.stop="toUserInfo(item.user.uid)">
						<view class="avatar">
							<image class="img" :src="item.user.avatar||''" mode="widthFix"></image>
						</view>
						<view class="nickname">
							<view>{{item.user.nickname}}</view>
							<view>发布件数：{{item.user.publish_num}} 件</view>
						</view>
					</view>
					<swiper class="slider-image" autoplay indicator-dots circular :duration="500">
						<swiper-item v-for="(pic, i) in item.slider_image" :key="i">
							<image class="slider-pic" :src="pic" mode="aspectFill"></image>
						</swiper-item>
					</swiper>
					<view class="goods-item v-ellip-2">[{{item.id}}]{{item.store_name}}</view>
					<view class="goods-item color-red">￥{{item.price}}
						<text v-if="item.wear_txt" class="separate">|</text>{{item.wear_txt||""}}
						<text v-if="item.made_at" class="separate">|</text>{{item.made_at||""}}
					</view>
					<view class="goods-item" v-if="item.cate_names">{{item.cate_names}}
						<text v-if="item.mType"><text class="separate">|</text>{{item.mType.title||""}}</text>
			
					</view>
					<view class="goods-item1" v-if="item.stock">
						<view>
							商品库存：<text class="color-desc">{{item.stock}}</text>
						</view>
						<view class="godetail" @click="toDetail(item)">
							查看详情
						</view>
					</view>
					<!-- 					<view class="goods-item" v-if="item.factory_name">生产厂家：<text class="color-desc">{{item.factory_name}}</text></view>
					<view class="goods-item" v-if="item.model">商品型号：<text class="color-desc">{{item.model}}</text></view>
					<view class="goods-item" v-if="item.piece_no">商品件号：<text class="color-desc">{{item.piece_no}}</text></view>
					<view class="goods-item" v-if="item.intro">商品配置：<text class="color-desc">{{item.intro}}</text></view>
					<view class="goods-item" v-if="item.from_addr">发货地址：<text class="color-desc">{{item.from_addr}}</text></view>
					<view class="goods-item" v-if="item.store_info">描述文字：<text class="color-desc">{{item.store_info}}</text></view>
					<view class="goods-item" v-if="item.service_desc">售后描述：<text class="color-desc">{{item.service_desc}}</text></view>
				 -->
			
				</view>
			</swiper-item>
		</swiper>
		<v-home></v-home>
	</view>
</template>

<script>
	let height = uni.getWindowInfo().windowHeight
	export default {
		data() {
			return {
				type: 0, // 列表类型：0推荐列表
				proid: 0,
				product: {},
				list: [],

				height: height,
				nextMarginHeight: height - height * 0.8-10,
				current: 0,
			}
		},
		onLoad(opts) {
			this.type = parseInt(opts.type || 0)
			this.proid = parseInt(opts.id || 0)
			this.getProductById(() => {
				this.init()
			})
		},
		methods: {
			toUserInfo(uid) {
				this.$tool.navto(`/pages/other/user_info?uid=${uid}`);
			},
			init() {
				switch (this.type) {
					case 0: // 推荐
						this.getRecommListExcludeId()
						break;

				}
			},
			getProductById(cb) {
				this.$http.get("v1/getProductById/" + this.proid).then(res => {
					this.product = res.data.product
					cb && cb()
				})
			},
			// 得到推荐商品列表（排除当前id）
			getRecommListExcludeId() {
				this.$http.get("v1/getRecommListExcludeId/" + this.proid).then(res => {
					// this.list = [this.product, ...res.data.list]
					this.list = res.data.list
				})
			},
			toDetail(item) {
				let id = item.product_id || item.id
				this.$tool.navto(`/pages/goods_details/index?id=${id}`);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.swiper-list {
		width: 100%;
		overflow: hidden;
		box-sizing: border-box;

		// background-color: #282828;
		.list {
			.tuijian {
				font-size: 32rpx;
				color: #000;
				text-align: center;
				margin: 40rpx 0 0rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.tuijianicon {
					width: 38rpx;
					height: 38rpx;
					margin-right: 10rpx;
				}

			}
			.item1{
				display: flex;
				justify-content: center;
				height: 100rpx;
			}

			.item {
				display: flex;
				justify-content: center;

				.inner {
					width: calc(100% - 10px);
					margin-top: 20px;
					border-radius: 10px;
					padding: 20rpx;

					// background-color: #ccc;
					.slider-image {
						height: calc(750rpx - 50px);

						.slider-pic {
							width: 100%;
							height: 100%;
							border-radius: 10px;
						}
					}

					.goods-item {
						margin-top: 10rpx;

						.separate {
							margin: 0 10rpx;
						}
					}

					.goods-item1 {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 10rpx;

						.separate {
							margin: 0 10rpx;
						}

						.godetail {
							width: 176rpx;
							height: 60rpx;
							text-align: center;
							line-height: 60rpx;
							color: #fff;
							border-radius: 50rpx;
							font-size: 27rpx;
							background: #2678FF;
						}
					}

					.user-info {
						display: flex;
						align-items: center;
						margin-bottom: 10rpx;

						.avatar {
							width: 10%;

							.img {
								width: 100%;
								border-radius: 50%;
							}
						}

						.nickname {
							display: flex;
							flex-direction: column;
							// align-items: center;
							margin-left: 10rpx;
						}
					}
				}
			}
		}
	}
</style>